﻿@{
    ViewBag.Title = "Routines";
}
@section Menu
{
    @Html.Partial("~/Views/Menu/Routine.cshtml", new ViewDataDictionary())
}
<script type="text/javascript">
    $(function () {
        $("#divSchedule").dialog({
            autoOpen: false,
            modal: true,
            resizable: false,
            width: 330,
            buttons: {
                Ok: function () {
                    //$("#formSchedule").submit();
                    $.ajax({
                        url: '@Url.Action("SaveSchedule")',
                        //data: { model: $("#formSchedule").serialize(), id: $('#selectedId').val() },
                        data: $("#formSchedule").serialize() + "&idRoutine=" + $('#selectedId').val() + "&repeat=" + getRepeatOnOrRepeatBy(),
                        type: "post",
                        success: function (json) {
                            //$('#hdnIdSaved').val(json.id);
                            //$("#divSchedule").dialog('close');
                            //window.location.href = '@Url.Action("Form")';
                            $("#divSchedule").dialog('close');
                        }
                    });
                },
                Cancel: function () {
                    $("#divSchedule").dialog('close');
                }
            }
        });
    });

    function openEscalationRoutineDialog() {
        $("#divEscalationRoutine").dialog({ modal: true, resizable: false, width: 750, height: 455 });
    }

    function openScheduleDialog(id) {
        $("#divSchedule").dialog('open');
        $('#selectedId').val(id);
    }

    //    function openUpdateRoutineDialog() {
    //        $("#divUpdateRoutine").dialog({ modal: true, resizable: false, width: 750, height: 455 });
    //    }
</script>
<div class="buttons">
    @Ajax.ActionLink("Create new", "ActionForm", null, new AjaxOptions { UpdateTargetId = "divUpdateRoutine", OnComplete = "openUpdateRoutineDialog" }, new { @class = "btn btn-primary" })
</div>
<br />
<br />
<input type="hidden" id="selectedId" />
<div id="divIndexRoutine">
    @Html.Action("Index")
</div>
<div id="divUpdateRoutine" title="Routine form">
</div>
<div id="divSchedule" title="Scheduling...">
</div>
<div id="divEscalationRoutine" title="Escalation">
</div>
